package com.wxlsoft.utils;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.List;

import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 * 克隆 sheet
 * @author wangxiaoliang
 */
public class SheetCloner {

	public static void cloneSheet(InputStream stream, List<String> names) {
		try (Workbook sheets = new XSSFWorkbook(stream)) {
			
			for (String name : names) {
				Sheet newSheet = sheets.cloneSheet(5);
				int sheetIndex = sheets.getSheetIndex(newSheet);
				sheets.setSheetName(sheetIndex, name);
			}
			
			sheets.removeSheetAt(5);
			int numberOfSheets = sheets.getNumberOfSheets();
			sheets.setSheetOrder("MAPPING_SLA", numberOfSheets - 1);
			
			sheets.write(new FileOutputStream("/javahome/wxl-repository/esb-excel-extract/src/main/resources/template2.xlsx"));
			
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e.getCause());
		}
		
	}
	
}
